/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.common.web;

import android.content.Context;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebView;
import com.qihoo.gamecenter.sdk.common.i.c;

public class a {
    public static boolean a(Context paramContext, String paramString1, String[] paramArrayOfString,
            String paramString2, String paramString3, String paramString4) {
        if ((TextUtils.isEmpty(paramString1)) || (paramArrayOfString == null) || (paramArrayOfString.length < 1)) {
            c.a("WebViewUtil", new Object[] { "The url or cookie is undefined" });
            return false;
        }
        CookieSyncManager.createInstance(paramContext);
        CookieManager localCookieManager = CookieManager.getInstance();
        localCookieManager.setAcceptCookie(true);
        for (String str : paramArrayOfString) {
            if (TextUtils.isEmpty(str))
                continue;
            str = str.trim();
            if ((!(TextUtils.isEmpty(paramString2))) && (str.indexOf("expires=") == -1)) {
                if (!(str.endsWith(";")))
                    str = str + "; ";
                str = str + "expires=" + paramString2.trim();
            }
            if ((!(TextUtils.isEmpty(paramString3))) && (str.indexOf("path=") == -1)) {
                if (!(str.endsWith(";")))
                    str = str + "; ";
                str = str + "path=" + paramString3.trim();
            }
            if ((!(TextUtils.isEmpty(paramString4))) && (str.indexOf("domain=") == -1)) {
                if (!(str.endsWith("; ")))
                    str = str + "; ";
                str = str + "domain=" + paramString4.trim();
            }
            c.a("WebViewUtil", new Object[] { "set cookie: ", str });
            localCookieManager.setCookie(paramString1, str);
        }
        CookieSyncManager.getInstance().sync();
        return true;
    }

    public static boolean a(String paramString) {
        if (TextUtils.isEmpty(paramString)) {
            c.a("WebViewUtil", new Object[] { "The url is undefined" });
            return false;
        }
        String str = b(paramString);
        c.a("WebViewUtil", new Object[] { "The Synced Cookie: ", str });
        return (!(TextUtils.isEmpty(str)));
    }

    public static String b(String paramString) {
        return CookieManager.getInstance().getCookie(paramString);
    }

    public static void a(Context paramContext) {
        c.a("WebViewUtil", new Object[] { "clear all cookies" });
        try {
            CookieSyncManager.createInstance(paramContext);
            CookieManager localCookieManager = CookieManager.getInstance();
            localCookieManager.removeAllCookie();
            CookieSyncManager.getInstance().sync();
        } catch (Exception localException) {
            c.b("WebViewUtil", new Object[] { localException.toString() });
        }
    }

    public static void a(WebView paramWebView) {
        c.a("WebViewUtil", new Object[] { "destroy webView" });
        if (paramWebView == null)
            return;
        try {
            ViewGroup localViewGroup = (ViewGroup) paramWebView.getParent();
            if (localViewGroup != null)
                localViewGroup.removeView(paramWebView);
            paramWebView.removeAllViews();
            paramWebView.clearHistory();
            paramWebView.destroy();
        } catch (Exception localException) {}
    }

    public static void a(WebView paramWebView, String paramString) {
        c.a("WebViewUtil", new Object[] { "webView=", (paramWebView != null) ? paramWebView.toString() : "null" });
        c.a("WebViewUtil", new Object[] { "loadUrl=", paramString });
        if ((paramWebView == null) || (TextUtils.isEmpty(paramString)))
            return;
        try {
            paramWebView.loadUrl("javascript:searchBoxJavaBridge_=\"\";void(0)");
            paramWebView.loadUrl(paramString);
        } catch (Exception localException) {}
    }
}